////////////////////////////////////////////////////////////////////////////////
/// @file    play_tone.c
/// @author  AE TEAM
/// @brief   THIS FILE PROVIDES ALL THE SYSTEM FUNCTIONS.
////////////////////////////////////////////////////////////////////////////////
/// @attention
///
/// THE EXISTING FIRMWARE IS ONLY FOR REFERENCE, WHICH IS DESIGNED TO PROVIDE
/// CUSTOMERS WITH CODING INFORMATION ABOUT THEIR PRODUCTS SO THEY CAN SAVE
/// TIME. THEREFORE, MINDMOTION SHALL NOT BE LIABLE FOR ANY DIRECT, INDIRECT OR
/// CONSEQUENTIAL DAMAGES ABOUT ANY CLAIMS ARISING OUT OF THE CONTENT OF SUCH
/// HARDWARE AND/OR THE USE OF THE CODING INFORMATION CONTAINED HEREIN IN
/// CONNECTION WITH PRODUCTS MADE BY CUSTOMERS.
///
/// <H2><CENTER>&COPY; COPYRIGHT MINDMOTION </CENTER></H2>
////////////////////////////////////////////////////////////////////////////////


// Define to prevent recursive inclusion
#define _PLAYTONE_C_

// Files includes
#include <stdio.h>
#include "HAL_conf.h"
#include "delay.h"
#include "uart.h"
#include "i2s_config.h"


////////////////////////////////////////////////////////////////////////////////
/// @addtogroup MM32_Example_Layer
/// @{

////////////////////////////////////////////////////////////////////////////////
/// @addtogroup MAIN
/// @{

////////////////////////////////////////////////////////////////////////////////
/// @addtogroup MAIN_Exported_Constants
/// @{



////////////////////////////////////////////////////////////////////////////////
/// @brief  This function is main entrance.
/// @param  None.
/// @retval None.
////////////////////////////////////////////////////////////////////////////////






s16 I2sSendu16[32 * 2 * 2] = {
    0, 0,
    3204, 3204,
    6285, 6285,
    9124, 9124,
    11612, 11612,
    13655, 13655,
    15172, 15172,
    16107, 16107,
    16423, 16423,
    16107, 16107,
    15172, 15172,
    13655, 13655,
    11613, 11613,
    9124, 9124,
    6285, 6285,
    3204, 3204,
    0, 0,
    -3204, -3204,
    -6285, -6285,
    -9124, -9124,
    -11612, -11612,
    -13655, -13655,
    -15172, -15172,
    -16107, -16107,
    -16423, -16423,
    -16107, -16107,
    -15172, -15172,
    -13655, -13655,
    -11613, -11613,
    -9124, -9124,
    -6285, -6285,
    -3204, -3204,
    0, 0,
    3204, 3204,
    6285, 6285,
    9124, 9124,
    11612, 11612,
    13655, 13655,
    15172, 15172,
    16107, 16107,
    16423, 16423,
    16107, 16107,
    15172, 15172,
    13655, 13655,
    11613, 11613,
    9124, 9124,
    6285, 6285,
    3204, 3204,
    0, 0,
    -3204, -3204,
    -6285, -6285,
    -9124, -9124,
    -11612, -11612,
    -13655, -13655,
    -15172, -15172,
    -16107, -16107,
    -16423, -16423,
    -16107, -16107,
    -15172, -15172,
    -13655, -13655,
    -11613, -11613,
    -9124, -9124,
    -6285, -6285,
    -3204, -3204
};


////////////////////////////////////////////////////////////////////////////////
/// @brief  start play the wave
/// @note   None
/// @param  None
/// @retval None
////////////////////////////////////////////////////////////////////////////////
void StartPlay(void)
{
    int i;

    i = 100000;
    while(i--);

    I2S_Stop();
    I2S_StartPlay(I2S_Standard_Phillips, I2S_DataFormat_16b, I2S_AudioFreq_44k);
}
////////////////////////////////////////////////////////////////////////////////
/// @brief  Play Sine wave through Dma Polling mode
/// @note   None
/// @param  None
/// @retval None
////////////////////////////////////////////////////////////////////////////////
void PlaySineDmaPollingDemo(void)
{

    RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA | RCC_AHBPeriph_GPIOB | RCC_AHBPeriph_GPIOC | RCC_AHBPeriph_GPIOD | RCC_AHBPeriph_GPIOE, ENABLE);
    RCC_AHBPeriphClockCmd(RCC_AHBENR_SDIO, ENABLE);

    I2S_CODEC_Init();

    StartPlay();
    I2S_PWR_ON();
    I2S3_TX_DMA2_Init((u16*)&I2sSendu16[0], 128);
    DMA_Cmd(DMA2_Channel2, ENABLE);
}


/// @}

/// @}

/// @}
